﻿using System.Web.Mvc;
using DotNetDream.Models;

namespace DotNetDream.Extenstion
{
    /// <summary>
    /// Base class for all controllers
    /// </summary>
    public abstract class DndController : Controller
    {
        protected DotNetDreamEntities Database = new DotNetDreamEntities();
        /// <summary>
        /// Navigate back to a return Url
        /// </summary>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        protected ActionResult NavigateBack(string returnUrl)
        {
            if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
            {
                return Redirect(returnUrl);
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
        }

        protected override void Dispose(bool disposing)
        {
            Database.Dispose();
            base.Dispose(disposing);
        }
    }
}